/*   1:    */ package com.atomikos.beans;
/*   2:    */ 
/*   3:    */ import java.beans.PropertyDescriptor;
/*   4:    */ import java.beans.PropertyEditor;
/*   5:    */ import java.beans.PropertyEditorManager;
/*   6:    */ import java.lang.reflect.InvocationTargetException;
/*   7:    */ import java.lang.reflect.Method;
/*   8:    */ 
/*   9:    */ class PropertyImp
/*  10:    */   implements Property
/*  11:    */ {
/*  12:    */   private PropertyDescriptor descriptor_;
/*  13:    */   private Object bean_;
/*  14:    */   private Editor editor_;
/*  15:    */   
/*  16:    */   PropertyImp(Object bean, PropertyDescriptor descriptor)
/*  17:    */     throws PropertyException
/*  18:    */   {
/*  19: 59 */     this.descriptor_ = descriptor;
/*  20: 60 */     this.bean_ = bean;
/*  21:    */     try
/*  22:    */     {
/*  23: 62 */       this.editor_ = createEditor();
/*  24:    */     }
/*  25:    */     catch (PropertyException ignore) {}
/*  26:    */   }
/*  27:    */   
/*  28:    */   protected PropertyDescriptor getPropertyDescriptor()
/*  29:    */   {
/*  30: 73 */     return this.descriptor_;
/*  31:    */   }
/*  32:    */   
/*  33:    */   protected Object getBean()
/*  34:    */   {
/*  35: 78 */     return this.bean_;
/*  36:    */   }
/*  37:    */   
/*  38:    */   public String getName()
/*  39:    */   {
/*  40: 87 */     return this.descriptor_.getName();
/*  41:    */   }
/*  42:    */   
/*  43:    */   public String getDescription()
/*  44:    */   {
/*  45: 96 */     String ret = null;
/*  46: 97 */     ret = this.descriptor_.getShortDescription();
/*  47: 98 */     if (ret == null) {
/*  48: 98 */       ret = getName();
/*  49:    */     }
/*  50: 99 */     return ret;
/*  51:    */   }
/*  52:    */   
/*  53:    */   public Class getType()
/*  54:    */   {
/*  55:108 */     return this.descriptor_.getPropertyType();
/*  56:    */   }
/*  57:    */   
/*  58:    */   public boolean isExpert()
/*  59:    */   {
/*  60:117 */     return this.descriptor_.isExpert();
/*  61:    */   }
/*  62:    */   
/*  63:    */   public boolean isPreferred()
/*  64:    */   {
/*  65:126 */     return this.descriptor_.isPreferred();
/*  66:    */   }
/*  67:    */   
/*  68:    */   public boolean isHidden()
/*  69:    */   {
/*  70:135 */     return this.descriptor_.isHidden();
/*  71:    */   }
/*  72:    */   
/*  73:    */   public boolean isReadOnly()
/*  74:    */   {
/*  75:144 */     return this.descriptor_.getWriteMethod() == null;
/*  76:    */   }
/*  77:    */   
/*  78:    */   public Object getValue()
/*  79:    */     throws PropertyException
/*  80:    */   {
/*  81:154 */     Object ret = null;
/*  82:    */     try
/*  83:    */     {
/*  84:156 */       Method method = this.descriptor_.getReadMethod();
/*  85:157 */       ret = method.invoke(this.bean_, null);
/*  86:    */     }
/*  87:    */     catch (InvocationTargetException e)
/*  88:    */     {
/*  89:162 */       throw new PropertyException("Error getting value of " + this.descriptor_.getName() + " " + e.getMessage(), e.getTargetException());
/*  90:    */     }
/*  91:    */     catch (Exception err)
/*  92:    */     {
/*  93:165 */       throw new PropertyException("Error getting value of " + this.descriptor_.getName(), err);
/*  94:    */     }
/*  95:167 */     return ret;
/*  96:    */   }
/*  97:    */   
/*  98:    */   public IndexedProperty getIndexedProperty()
/*  99:    */   {
/* 100:176 */     return null;
/* 101:    */   }
/* 102:    */   
/* 103:    */   public void setValue(Object arg)
/* 104:    */     throws ReadOnlyException, PropertyException
/* 105:    */   {
/* 106:187 */     if (isReadOnly()) {
/* 107:188 */       throw new ReadOnlyException("Property is readonly");
/* 108:    */     }
/* 109:    */     try
/* 110:    */     {
/* 111:193 */       Object[] args = new Object[1];
/* 112:194 */       args[0] = arg;
/* 113:195 */       Method method = this.descriptor_.getWriteMethod();
/* 114:196 */       method.invoke(this.bean_, args);
/* 115:    */     }
/* 116:    */     catch (Exception e)
/* 117:    */     {
/* 118:199 */       e.printStackTrace();
/* 119:200 */       throw new PropertyException("Error in setting value", e);
/* 120:    */     }
/* 121:    */   }
/* 122:    */   
/* 123:    */   private Editor createEditor()
/* 124:    */     throws PropertyException
/* 125:    */   {
/* 126:212 */     Editor ret = null;
/* 127:213 */     PropertyEditorComponent component = null;
/* 128:214 */     Class wrapperClass = PrimitiveClasses.getWrapperClass(getType());
/* 129:216 */     if (wrapperClass != null)
/* 130:    */     {
/* 131:217 */       if (wrapperClass.equals(Boolean.class)) {
/* 132:218 */         component = new CheckboxComponent(this);
/* 133:    */       } else {
/* 134:221 */         component = new TextFieldComponent(this, PrimitiveClasses.isDecimalClass(wrapperClass));
/* 135:    */       }
/* 136:    */     }
/* 137:225 */     else if (String.class.equals(getType()))
/* 138:    */     {
/* 139:226 */       if (getAllowedValues() != null) {
/* 140:226 */         component = new ComboBoxComponent(this);
/* 141:    */       } else {
/* 142:227 */         component = new TextFieldComponent(this);
/* 143:    */       }
/* 144:    */     }
/* 145:229 */     else if (getIndexedProperty() != null) {
/* 146:231 */       component = new TableComponent(getIndexedProperty());
/* 147:    */     }
/* 148:235 */     if (component != null)
/* 149:    */     {
/* 150:236 */       PropertyEditor pedit = new DefaultPropertyEditor(component, getAllowedValues());
/* 151:    */       
/* 152:    */ 
/* 153:239 */       ret = new EditorImp(this, pedit);
/* 154:    */     }
/* 155:242 */     return ret;
/* 156:    */   }
/* 157:    */   
/* 158:    */   public Editor getEditor()
/* 159:    */   {
/* 160:251 */     return this.editor_;
/* 161:    */   }
/* 162:    */   
/* 163:    */   public String[] getAllowedValues()
/* 164:    */   {
/* 165:260 */     String[] ret = null;
/* 166:261 */     PropertyEditor pedit = null;
/* 167:    */     try
/* 168:    */     {
/* 169:265 */       Class clazz = this.descriptor_.getPropertyEditorClass();
/* 170:266 */       if (clazz != null) {
/* 171:266 */         pedit = (PropertyEditor)clazz.newInstance();
/* 172:    */       }
/* 173:    */     }
/* 174:    */     catch (Exception e) {}
/* 175:273 */     if (pedit == null) {
/* 176:274 */       pedit = PropertyEditorManager.findEditor(this.descriptor_.getPropertyType());
/* 177:    */     }
/* 178:277 */     if (pedit != null) {
/* 179:278 */       ret = pedit.getTags();
/* 180:    */     }
/* 181:280 */     return ret;
/* 182:    */   }
/* 183:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.beans.PropertyImp
 * JD-Core Version:    0.7.0.1
 */